using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using TrainTicket.DAO;
using TrainTicket.VO;

namespace TrainTicket.TRAIN
{
    public class RouterTRAIN
    {
        private RouterDAO _routerDAO;
        public RouterTRAIN()
        {
            _routerDAO = new RouterDAO();
        }

        public DataTable GetAllRouter()
        {
            return _routerDAO.GetAllRouter();
        }

        public DataTable GetAllStartPlace()
        {
            return _routerDAO.GetAllStartPlace();
        }

        public DataTable GetAllDestinationPlace()
        {
            return _routerDAO.GetAllDestinationPlace();
        }

        public DataTable GetAllDestinationPlaceByStartPlace(string startPlace)
        {
            return _routerDAO.GetAllDestinationPlaceByStartPlace(startPlace);
        }

        public int InsertRouter(Router router)
        {
            return _routerDAO.InsertRouter(router);
        }

        public int DeleteRouter(Router router)
        {
            return _routerDAO.DeleteRouter(router);
        }

        public Router GetRouterById(int routerID)
        {
            List<Router> list = new List<Router>();
            DataTable dbTable = _routerDAO.GetRouterById(routerID);
            Router router = new Router();
            foreach (DataRow dr in dbTable.Rows)
            {
                router.RouterID = int.Parse(dr["RouterID"].ToString());
                router.RouterName = dr["RouterName"].ToString();
                router.StartPlace = dr["StartPlace"].ToString();
                router.DestinationPlace = dr["DestinationPlace"].ToString();
                router.Long = int.Parse(dr["Long"].ToString());
                router.Description = dr["Description"].ToString();
                router.CreateDate = dr["CreateDate"].ToString();
                router.Status = dr["Status"].ToString();
            }
            return router;
        }

        public bool CheckRouterExitsInsert(string routerName)
        {
            int check = _routerDAO.CheckRouterExitsInsert(routerName);
            if (check > 0)
                return true;
            else
                return false;
        }

        public bool CheckRouterExitsUpdate(int routerID, string routerName)
        {
            int check = _routerDAO.CheckRouterExitsUpdate(routerID, routerName);
            if (check > 0)
                return true;
            else
                return false;
        }

        public int UpdateRouter(Router router)
        {
            return _routerDAO.UpdateRouter(router);
        }

    }
}
